/*
package von.seiji.cn.ai;

public class Joone implements NeuralNetListener{
    private NeuralNet neuralNet;
    private Monitor monitor;
    private SigmoidLayer out, hidden;
    private LinearLayer in;

    public static void main(String[] args) {
        Xor xor = new Xor();
        xor.init_nulnetwork();
        xor.dualData("res/xor.txt", "res/result.txt");
        // xor.name("res/xor.txt", "res/result.txt");
        try { Thread.sleep(1000); } catch (InterruptedException doNothing) { }
        xor.interrogate();
    }

    private void interrogate() {

        double[][] inputArray = new double[][] { { 0.0, 1.0 } };
        // set the inputs
        neuralNet.getMonitor().setLearning(false);

        MemoryInputSynapse inputSynapse = new MemoryInputSynapse();
        inputSynapse.setInputArray(inputArray);
        inputSynapse.setAdvancedColumnSelector("1,2");

        neuralNet.removeAllInputs();
        neuralNet.removeAllOutputs();
        neuralNet.addInputSynapse(inputSynapse);
        MemoryOutputSynapse memOut = new MemoryOutputSynapse();
        neuralNet.addOutputSynapse(memOut);
        if (neuralNet != null) {
            neuralNet.getMonitor().setSingleThreadMode(false);
            neuralNet.go();
            for (int i = 0; i < 4; i++) {
                double[] nextPattern = memOut.getNextPattern();
                System.out.println(nextPattern[0]);
            }
            System.exit(0);
        }
    }

    public void dualData(String inpath, String outpath) {

        // 输入数据突触
        FileInputSynapse inputSynapse = new FileInputSynapse();
        inputSynapse.setInputFile(new File(inpath));
        inputSynapse.setAdvancedColumnSelector("1,2");
        // 传入数据突触
        in.addInputSynapse(inputSynapse);

        // 训练突触
        TeachingSynapse Teaching = new TeachingSynapse();
        // 结果对应
        FileInputSynapse in_resultsynapse = new FileInputSynapse();
        in_resultsynapse.setInputFile(new File(inpath));
        in_resultsynapse.setAdvancedColumnSelector("3");

        // 期望结果
        Teaching.setDesired(in_resultsynapse);

        // 输出数据突触
        out.addOutputSynapse(Teaching);
        */
/* Creates the error output file *//*

        FileOutputSynapse error = new FileOutputSynapse();
        error.setFileName(outpath);
        // error.setBuffered(false);
        Teaching.addResultSynapse(error);
        neuralNet.setTeacher(Teaching);

        monitor.setLearning(true);
        monitor.setTrainingPatterns(4);
        monitor.setTotCicles(2000);
        neuralNet.go();
    }

    public void init_nulnetwork() {
        // 构造三个神经网络
        in = new LinearLayer("in");
        out = new SigmoidLayer("out");
        hidden = new SigmoidLayer("hidden");

        // 定义每个网络的神经数
        in.setRows(2);
        hidden.setRows(3);
        out.setRows(1);

        // 创建神经突触
        FullSynapse synapseone = new FullSynapse();
        FullSynapse synapsetwo = new FullSynapse();

        // 连接突触 in->hidden
        in.addOutputSynapse(synapseone);
        hidden.addInputSynapse(synapseone);
        // hidden>out
        out.addInputSynapse(synapsetwo);
        hidden.addOutputSynapse(synapsetwo);

        // 创建容器
        neuralNet = new NeuralNet();
        neuralNet.addLayer(in, NeuralNet.INPUT_LAYER);
        neuralNet.addLayer(out, NeuralNet.OUTPUT_LAYER);
        neuralNet.addLayer(hidden, NeuralNet.HIDDEN_LAYER);
        neuralNet.addNeuralNetListener(this);

        monitor = neuralNet.getMonitor();
        monitor.addNeuralNetListener(this);
        // 学习速度
        monitor.setLearningRate(0.8);
        // 学习梯度
        monitor.setMomentum(0.9);
    }

    @Override
    public void cicleTerminated(NeuralNetEvent arg0) {

    }

    @Override
    public void errorChanged(NeuralNetEvent arg0) {
        Monitor source = (Monitor) arg0.getSource();
        if (source.getCurrentCicle() % 100 == 0)
            System.out.println(source.getCurrentCicle() + " epochs remaining - RMSE = " + source.getGlobalError());
    }

    @Override
    public void netStarted(NeuralNetEvent arg0) {
        System.out.println("star ..............");
    }

    @Override
    public void netStopped(NeuralNetEvent arg0) {
    }

    @Override
    public void netStoppedError(NeuralNetEvent arg0, String arg1) {

    }
}
*/
